package com.zengde.chapter1.main;

import com.zengde.chapter1.config.AppConfig;
import com.zengde.chapter1.pojo.BusinessPerson;
import com.zengde.chapter1.pojo.DataBaseProperties;
import com.zengde.chapter1.pojo.User;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class IoCTest {
    public static void main(String[] args) {
        // 使用配置文件AppConfig.java创建IoC容器
        var ctx = new AnnotationConfigApplicationContext(AppConfig.class);
        try {
            // 通过getBean()方法获取Bean
            /*var businessPerson = ctx.getBean(BusinessPerson.class);
            businessPerson.service();*/


            var dataBaseProperties = ctx.getBean(DataBaseProperties.class);
            System.out.println(dataBaseProperties.getUsername());
            System.out.println(dataBaseProperties.getPassword());

        } finally {
            // 关闭IoC容器
            ctx.close();
        }

    }
}